package com.goldsprite.microhorigame.screens.examples.spinegfsmexamples;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.goldsprite.microhorigame.screens.basics.ExampleGScreen;
import com.goldsprite.gameframeworks.input.*;

public class SpineGFsmExample extends ExampleGScreen {
	@Override
	public String getIntroduction() {
		return "SpineGFSM演示";
	}
	private SpineCharacter character;
	private PolygonSpriteBatch batch;
	private OrthographicCamera camera;
	private Viewport viewport;

	// 固定虚拟分辨率
	private final float VIRTUAL_WIDTH = Env.WORLD_WIDTH;
	private final float VIRTUAL_HEIGHT = Env.WORLD_HEIGHT;

	@Override
	public void create() {
		batch = new PolygonSpriteBatch();

		// 设置相机
		camera = new OrthographicCamera();
		viewport = new FitViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, camera);
		camera.setToOrtho(false, Env.WORLD_WIDTH, Env.WORLD_HEIGHT);

		// 创建角色（固定使用骑士）
		character = new SpineCharacter(Env.getCurrentCharacterType());
		character.create();

		// 调整角色位置到视口中心
		character.setPosition(VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2);
	}

	@Override
	public void render(float delta) {
		super.render(delta);

		logic();

		// 更新
		character.update(delta);

		// 渲染
		batch.setProjectionMatrix(camera.combined);
		character.render(batch);
	}

	private void logic() {
	}

	@Override
	public void resize(int width, int height) {
		viewport.update(width, height);
	}

	@Override
	public void dispose() {
		batch.dispose();
		character.dispose();
	}

	@Override
	public void show(){
		super.show();
		GameInputSystem.showAndroidKeyBoard(true);
	}

	@Override
	public void hide(){
		super.hide();
		GameInputSystem.showAndroidKeyBoard(false);
	}
}
